package role

import (
	"context"
	"goAdminV1/internal/model"
	"goAdminV1/utility"

	"goAdminV1/api/role/v1"
)

func (c *ControllerV1) RoleList(ctx context.Context, req *v1.RoleListReq) (res *v1.RoleListRes, err error) {
	// 调用 model 层获取角色列表
	data, err := model.GetRoles(ctx, req.Limit, req.Page, req.RoleName)
	if err != nil {
		return nil, utility.Error(utility.CodeOperation, err)
	}

	// 填充响应结构体
	res = &v1.RoleListRes{
		PaginatedResponse: *utility.SuccessWithPagination(
			data.Roles, // 实际数据
			req.Limit,  // 每页条数
			data.Total, // 总条数
			"列表获取成功",   // 自定义成功消息
		),
	}
	return res, nil
}
